"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = __importDefault(require("path"));
const jimp_1 = __importDefault(require("jimp"));
function uploadhandle(req, res, next) {
    return __awaiter(this, void 0, void 0, function* () {
        const oImgPath = path_1.default.join(__dirname, "../../public/img/hutao.png");
        const nImgPath = path_1.default.join(__dirname, "../../public" + req.query.fileurl);
        const outPutPath = path_1.default.join(__dirname, "../../public/upload");
        fun(oImgPath, nImgPath, outPutPath);
        next();
    });
}
exports.default = uploadhandle;
function fun(wf, of, target, p = 5, mar = 0.05) {
    return __awaiter(this, void 0, void 0, function* () {
        const [n, o] = yield Promise.all([jimp_1.default.read(wf), jimp_1.default.read(of)]);
        const cp = o.bitmap.width / n.bitmap.width;
        wf.search((cp / p));
        const r = o.bitmap.width * mar;
        const b = o.bitmap.height * mar;
        const x = o.bitmap.width - r - n.bitmap.width;
        const y = o.bitmap.height - b - n.bitmap.height;
        o.composite(n, x, y, {
            mode: jimp_1.default.BLEND_ADD,
            opacityDest: 1,
            opacitySource: 0.6,
        });
        o.write(path_1.default.resolve(target, path_1.default.basename(of)));
    });
}
